home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / qed6 < prev    next >
Text File  |  1987-10-10  |  10KB  |  486 lines

  1. /*  VERSION 0014  (DATE: 27/02/87)  (TIME: 12:57)  */
  2. /*
  3.     e (qed) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec    1984:    BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  10.               March        1985:    BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  11.  
  12.  
  13.     FUNCTIONS: blockpos,blockops,putpart,listfile,reform
  14.  
  15.     PURPOSE: performs block commands
  16.  
  17. */
  18.  
  19. #include "qed.h"
  20.  
  21. char *firstwhite();
  22.  
  23. blockpos(oldpos)
  24. int oldpos;
  25. {
  26.     char c;
  27.     int to;
  28.  
  29.     if (oldpos) putstr("| or |P|rev.");
  30.     do {
  31.         resetcursor();
  32.         switch ((c=getkey())) {
  33.         case DOWNKEY    : 
  34.             moveline(1); 
  35.             break;
  36.         case UPKEY    : 
  37.             moveline(-1); 
  38.             break;
  39.         case LEFTKEY    : 
  40.             movechar(-1); 
  41.             break;
  42.         case RIGHTKEY    : 
  43.             movechar(1); 
  44.             break;
  45.         case LEFTWKEY    : 
  46.             moveword(-1); 
  47.             break;
  48.         case RIGHTWKEY    : 
  49.             moveword(1);  
  50.             break;
  51.         case BOLKEY    : 
  52.             sync(0);
  53.             break;
  54.         case EOLKEY    : 
  55.             sync(strlen(text)); 
  56.             break;
  57.         case UPPAGE    : 
  58.             movepage(-1); 
  59.             break;
  60.         case DOWNPAGE    : 
  61.             movepage(0); 
  62.             break;
  63.         case HOMEKEY    : 
  64.             if (jumpline(lastl-cline)) sync(strlen(text));
  65.             break;
  66.         case BOFKEY    : 
  67.             if (jumpline(1-cline)) sync(0);
  68.             break;
  69.         case JUMPKEY    :
  70.             if (expert) xprtmess("Jump to: ");
  71.             else putmess("Jump to? ");
  72.             scans(ans,6);
  73.             if ((to=atoi(ans)))
  74.                 jumpline(to-cline);
  75.             break;
  76.         case QWIKKEY    :
  77.             info();
  78.             break;
  79.         case REPKEY    : 
  80.             repeat=YES; 
  81.             dofindrep(1); 
  82.             repeat=NO;
  83.             break;
  84.         case 'p'    :
  85.         case 'P'    : 
  86.             if (oldpos) return PREV;
  87.             break;
  88.         case ESCKEY    :
  89.             return FAIL;
  90.         default        : 
  91.             ;
  92.             }
  93.         } 
  94.     while (c != CR);
  95.     return cline;
  96. }
  97.  
  98. blockops()
  99. {
  100.     int oldcline, oldcharn, oldto, oldfrom, op;
  101.     int l, ll, line, *t, shifts, shiftx, cp;
  102.     char  *txt, c, shift[LLIM];
  103.  
  104.     puttext();
  105.     oldcline=cline; 
  106.     oldcharn=charn; 
  107.     oldfrom=from;
  108.     oldto=to;
  109.     if (expert) xprtmess("Q/X/R/B/J-rep ? ");
  110.     else
  111.      putmess("Q|uit, |X|it w/ save, |R|ead file, |B|lock moves, |J|ump repeat ? ");
  112.     while ((op = getlow()) != 'q' && op != 'x' && op != 'r' && op != 'b' &&
  113.          op != 'j' && op != ESCKEY);
  114.     if (op == ESCKEY) goto clrblk;
  115.     putch(op);
  116.     switch (op)  {
  117.     case 'q':
  118.         return('q');
  119.         break;
  120.     case 'x':
  121.         return('x');
  122.         break;
  123.     case 'r':
  124.         return ('r');
  125.         break;
  126.     case 'j':
  127.         if (jmpto > 1) jumpline(jmpto-cline);
  128.         else calcjmp();
  129.         if (expert) xmessoff();
  130.         return (NO);
  131.         break;
  132.     default:
  133.     optmess:
  134. #if WWRAP
  135.     if (expert) xprtmess("W/P/S/R/M/C/D ? ");
  136.     else
  137.      putmess("W|rite to file, |P|rint, |S|hift, |R|eformat, |M|ove, |C|opy, or |D|elete block ? ");
  138.     while ((op=getlow()) != 'w' && op != 'p' && op != 's' && op != 'r'
  139.             && op != 'm' && op != 'c' && op != 'd' && op != ESCKEY);
  140. #else
  141.     if (expert) xprtmess("W/P/S/M/C/D ? ");
  142.     else
  143.      putmess("W|rite to file, |P|rint, |S|hift, |M|ove, |C|opy, or |D|elete block ? ");
  144.     while ((op=getlow()) != 'w' && op != 'p' && op != 's'
  145.             && op != 'm' && op != 'c' && op != 'd' && op != ESCKEY);
  146. #endif
  147.     if (op == ESCKEY) goto clrblk;
  148.     switch (op) {
  149.     case 'w':
  150.         if (expert) putstr("W");
  151.         else putstr("Write");
  152.         break;
  153.     case 'p':
  154.         if (expert) putstr("P");
  155.         else putstr("Print");
  156.         break;
  157.     case 's':
  158.         if (expert) putstr("S");
  159.         else putstr("Shift");
  160.         break;
  161. #if WWRAP
  162.     case 'r':
  163.         if (expert) putstr("R");
  164.         else putstr("Reformat");
  165.         break;
  166. #endif
  167.     case 'm': 
  168.         if (expert) putstr("M");
  169.         else putstr("Move");
  170.         break;
  171.     case 'c': 
  172.         if (expert) putstr("C");
  173.         else putstr("Copy");
  174.         break;
  175.     case 'd': 
  176.         if (expert) putstr("D");
  177.         else putstr("Delete");
  178.         break;
  179.         }
  180.     from=cline;
  181.     to=0;
  182.     blocking=YES;
  183.     if (expert) xprtmess("Cursor on end line + <CR>");
  184.     else
  185.      putmess("|Put cursor on line |end|ing block and press [return]");
  186.     if ( (to=blockpos(oldto)) == FAIL) {
  187.         to=cline;
  188.         goto abort;
  189.         }
  190.     if (to == PREV) {
  191.         moveline(oldfrom-cline);
  192.         from=cline;
  193.         moveline(oldto-cline);
  194.         to=cline;
  195.         }
  196.     if (to < from) {
  197.         l=to; 
  198.         to=from; 
  199.         from=l;
  200.         }
  201.     switch (op) {
  202.     case 'w':
  203.         if (expert) xprtmess("File? ");
  204.         else putmess("File to write to? ");
  205.         if (scans(name,15) != ESCKEY)
  206.             if (exists(name)) writefile(from,to,name,name,NO);
  207.         break;
  208.     case 'p':
  209.         listfile(from,to);
  210.         break;
  211.     case 's':
  212.         if (expert) xprtmess("Changes: ");
  213.         else
  214.          putmess("Delete/insert spaces/tabs| to shift line, and press [return]");
  215.         moveline(from-cline);
  216.         sync(0);
  217.         resetcursor();
  218.         shifts=0;
  219.         while ( (c=getkey()) != CR) {
  220.             switch (c) {
  221.             case DELRIGHT:     
  222.                 if ((text[0] == ' ') || (text[0] == '\t') ||
  223.                     ( (text[0]>0x20) && (text[0]<0x80)) )
  224.                     deletechar(0);
  225.                 break;
  226.             case ' ':
  227.                 insertchar(' ');
  228.                 break;
  229.             case TAB:
  230.                 insertchar('\t');
  231.                 break;
  232.             case ESCKEY:
  233.                 goto abort;
  234.             default:        /*28.i.87: add chars to lines*/
  235.                 if( (c>0x20) && (c<0x80)) insertchar(c);
  236.             }
  237.             shift[shifts++]=c;
  238.             sync(0);
  239.             resetcursor();
  240.         }
  241.         altered=YES;
  242.         puttext();
  243.         for (l=from+1; l <= to; l++) {
  244.             gettext(l);
  245.             for (shiftx=0; shiftx < shifts; shiftx++) {
  246.                 switch((c=shift[shiftx])) {
  247.                 case DELRIGHT:     
  248.                     /*if (*(txt=&text[0]) == ' ' || *txt == '\t') [28.i.87]*/
  249.                     if(*(txt=&text[0]))
  250.                         while ( (*txt=*(txt+1))) txt++;
  251.                     break;
  252.                 /*  ORIGINAL
  253.                 case ' ':
  254.                 case TAB:
  255.                     if ((cp=strlen(text)) < (LLIM-1)) {
  256.                         for (; cp >= 0; cp--)
  257.                             text[cp+1]=text[cp];
  258.                         text[0]= (c == ' ' ? ' ':'\t');
  259.                     }
  260.                     break;
  261.                 */ /*28.I.87*/
  262.                 default:
  263.                     if ((cp=strlen(text)) < (LLIM-1)) {
  264.                         for (; cp >= 0; cp--)
  265.                             text[cp+1]=text[cp];
  266.                         /*text[0]= (c == ' ' ? ' ':'\t');*/
  267.                         if(c==TAB) text[0]='\t';
  268.                         else text[0]=c;
  269.                     }
  270.                 }
  271.             }
  272.             altered=YES;
  273.             puttext();
  274.         }
  275.         changed=YES;
  276.         break;
  277. #if WWRAP
  278.     case 'r':
  279.         reform(from,to);
  280.         changed=YES;
  281.         break;
  282. #endif
  283.     case 'd':
  284.         deltp(from,to-from+1);
  285.         gettext(loc(from,-1));
  286.         charn=adjustc(oldcharn);
  287.         from=to=0;
  288.         changed=YES;
  289.         break;
  290.     case 'm':
  291.     case 'c':
  292.         if (expert) xprtmess("Cursor on line above block + <CR>");
  293.         else
  294.          putmess("|Put cursor on |line under which  block is to go |and press [return]");
  295.         if ( (cline=line=blockpos(0)) == FAIL) {
  296.             cline=oldcline; 
  297.             break;
  298.             }
  299.         for (l=from; l <= to; l++) {
  300.             if ((line=inject(line,getline(l))) == FAIL) break;
  301.             if (op == 'm') {
  302.                 deltp( (l<line?l:l+1),1);
  303.                 if (to < line) {
  304.                     to--; 
  305.                     l--; 
  306.                     line--; 
  307.                     cline--;
  308.                     }
  309.                 }
  310.             else {
  311.                 if (to >= line) to++;
  312.                 if (l >= line) l++;
  313.                 if (l == cline) l=line;
  314.                 }
  315.             }
  316.         from=cline+1; 
  317.         to=line;
  318.         changed=YES;
  319.         break;
  320.         }
  321. abort:
  322.     blocking=NO;
  323.     switch (op) {
  324.     case 'w':
  325.     case 'p':
  326.     case 's':
  327.         gettext(oldcline);
  328.         charn=oldcharn;
  329.         putpart(from,to);
  330.         break;
  331.     case 'd':
  332.         putpart(cline,cline+SHEIGHT);
  333.         break;
  334. #if WWRAP
  335.     case 'r':
  336. #endif
  337.     case 'm':
  338.     case 'c':
  339.         putpage();
  340.         break;
  341.         }
  342. clrblk:
  343.     if (expert) xmessoff();
  344.     return NO;
  345.     }   /* outer case */
  346. }      /* func blockops */
  347.  
  348. putpart(start,fin)
  349. int start,fin;
  350. {
  351.     int l, y;
  352.  
  353.     if (start < pfirst) putpage();
  354.     else
  355.     for (l=start, y=topline+(start-pfirst); l <= fin && y <= SHEIGHT;
  356.             l++, y++) {
  357.             if (l == cline) cursory=y;
  358.         putline(l,y);
  359.         }
  360. }
  361.  
  362. listfile(from,to)
  363. int from,to;
  364. {    /*10*/
  365.     int l,cp,i;
  366.     char *t;
  367.  
  368.     puttext();
  369.     for (l=from; l<=to; l++) {    /*20*/
  370.         if (l%10 == 0) putlineno(l);
  371.         for (cp=0, t=getline(l); *t; t++)
  372.             if (*t == '\t') for (i=tabwidth-cp%tabwidth; i>0 ; cp++, i--)
  373.                 _os(LSTOUT,' ');
  374.             else {    /*30*/
  375.                 /*if (*t > CTRL) _os(LSTOUT,*t);*/
  376. #if PRINTALL
  377.                 _os(LSTOUT,*t);
  378. #else
  379.                 if (*t > 0x19) _os(LSTOUT,*t);        /* send some ctrl char*/
  380.                 else {    /*40*/                        /* for OKI & CITOH */
  381.                     switch (*t) {    /*50*/
  382.                     case (0x08):
  383.                     case (0x0a):
  384.                     case (0x0c):
  385.                     case (0x0d):
  386.                     case (0x18):
  387.                         _os(LSTOUT,*t);
  388.                         break;
  389.                     default:  {        /*60*/
  390.                         _os(LSTOUT,'^');
  391.                         _os(LSTOUT,*t+64);
  392.                         }    /*60*/
  393.                     }    /*50*/
  394.                     }    /*40*/
  395. #endif
  396.                 cp++;
  397.                 }    /*30*/
  398.         _os(LSTOUT,'\r'); 
  399.         _os(LSTOUT,'\n');
  400.         if (testkey() == ESCKEY) {    /*70*/
  401.             error("Listing aborted